package com.tn.task;



import com.tn.controller.alarm.common.model.weigh.vo.LedInfoVo;

import com.tn.socket.LEDSocket;
import com.tn.utils.redis.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
@Slf4j
public class LedTask {

    @Autowired
    private LEDSocket socket;

    @Autowired
    private ThreadPoolTaskExecutor executor;

    @Scheduled(cron = "0/2 * * * * ?")
    public void executeRedisTask() {

        Map<String, LedInfoVo> map = RedisUtils.getCacheMap("led_task");
        //查询所有的led屏报文
        executor.execute(()->{
            for (String s : map.keySet()) {
                LedInfoVo ledInfoVo = map.get(s);
                socket.ledDisplay(ledInfoVo);
            }
        });
    }
}
